package net.pimpas.web.jsf.renderers.util.html;

import java.io.IOException;

import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;

import net.pimpas.web.jsf.components.UIComponentPimpasBase;

import org.apache.myfaces.shared_impl.renderkit.html.HTML;

public abstract class HtmlRendererBase {
	
	public static void writeBaseHtmlAttributes(FacesContext context, UIComponentPimpasBase component)
	throws IOException{
		
		ResponseWriter writer = context.getResponseWriter();
		
		if(component.getId() == null || component.getId().trim().equals(""))
			component.setId(context.getViewRoot().createUniqueId());
		
		if(component.getNoId()==null || component.getNoId().equals(Boolean.FALSE))
			writer.writeAttribute(HTML.ID_ATTR, component.getClientId(context), null);
		
		if(component.getStyleClass() != null)
			HtmlRendererUtils.writeHtmlAttribute(component, writer, "styleClass", HTML.CLASS_ATTR);
		if(component.getStyle() != null)
			HtmlRendererUtils.writeHtmlAttribute(component, writer, "style", HTML.STYLE_ATTR);
		if(component.getTabIndex() != null)
			HtmlRendererUtils.writeHtmlAttribute(component, writer, "tabIndex", "tabIndex");
		if(component.getAlign() != null)
			HtmlRendererUtils.writeHtmlAttribute(component, writer, "align", "align");
	}
}